package com.shenganyuan.smac.common.utils;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;

import com.oklib.utils.view.ToastUtils;
import com.tbruyelle.rxpermissions2.RxPermissions;


public class PhoneUtil {

    public static void callPhone(Activity context, String phoneNumber) {
        callPhone(context, Uri.parse("tel:" + phoneNumber));
    }

    public static void callPhone(Activity context, Uri url) {
        RxPermissions rxPermissions = new RxPermissions(context);
        rxPermissions.request(Manifest.permission.CALL_PHONE)
                .subscribe(granted -> {
                    if (granted) {
                        Intent intent = new Intent();
                        intent.setAction(Intent.ACTION_DIAL);
                        intent.setData(url);
                        context.startActivity(intent);
                    } else {
                        ToastUtils.showToast(context, "请允许相关权限，才能拨打电话");
                    }
                });
    }

}
